<?php echo $this->render('layouts/__header.phtml'); ?><?php echo $this->render('layouts/__nav.phtml'); ?>
<style>
<!--
div#userlist,#statuslist,#propertylist{
	display:none;
}
label.userlist,label.statuslist,label.propertylist {
	width:165px;
	display:block;
	float:left;
	padding:5px 0px;
}
div.choosemenu{
	clear:both;
	text-align:right;
	padding-right:10px;
}
-->
</style>
<script type="text/javascript" src="/js/calendar/calendar.js"></script>
<script type="text/javascript" src="/js/calendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="/js/calendar/calendar-setup.js"></script>
<style type="text/css">
@import url(/js/calendar/calendar.css); 
</style>
<script type="text/javascript" src="/js/rpt/swfobject.js"></script>
<script type="text/javascript">
window.addEvent('domready', function(){	
	Calendar.setup({inputField:"date_start",ifFormat:"%Y-%m-%d",button:"calendarBeginButton",singleClick:true,step:1});
	Calendar.setup({inputField:"date_end",ifFormat:"%Y-%m-%d",button:"calendarEndButton",singleClick:true,step:1});
	Calendar.setup({inputField:"date_start",ifFormat:"%Y-%m-%d",button:"vBeginDate",singleClick:true,step:1});
	Calendar.setup({inputField:"date_end",ifFormat:"%Y-%m-%d",button:"vEndDate",singleClick:true,step:1});
	changeData();	
});	

var engineers = "";
var statuss = "";
var propertys = "";
function changeData(){
	var request_uri = '/report/rptdataewe/show/list';
	request_uri += '/dates/'+$('date_start').value+'/datee/'+$('date_end').value;	
	request_uri += '/dimension/'+$('dimension').value; 
	if (engineers != "") request_uri += "/engineers/" + engineers;
	if (statuss != "") request_uri += "/statuss/" + statuss;
	if (propertys != "") request_uri += "/propertys/" + propertys;
		 
	$('loadingbox').setStyle('display', 'block');	
	new Ajax(request_uri, {
		method: 'get',
		evalScripts : true,		
		update: $('listing'),
		onComplete: function(){
			$('loadingbox').setStyle('display', 'none');			
			$('listing').setStyle('display', 'block');
		}
	}).request();
}

function setData(request_uri) {
	   var flashMovie;
	   flashMovie = document.getElementById("amrpt");
	      if (flashMovie) {      
	      new Ajax(request_uri, {
			method: 'get',
			evalScripts : true,		
			onComplete: function(){						
				flashMovie.setData(this.response.text);
				
			}
		}).request(); 
      }
}

function chooseUser() {
	PopBox.pop(document.getElementById("userlist").innerHTML);
	var engineer = ","+engineers
	$('popbox-content').getElements('input[type=checkbox]').each(function(item,index){
		if (engineer.indexOf(","+item.value) != -1) {
			item.checked = true;
		}
	});
}
function choosedUser() {	
	engineers = "";
	$('popbox-content').getElements('input[type=checkbox]').each(function(item,index){
		if (item.checked) {
			engineers += "," + item.value;
		}
	});
	engineers = engineers.substring(1); //delete first ","
	PopBox.close();
	changeData();
}

function chooseStatus() {
	PopBox.pop(document.getElementById("statuslist").innerHTML);
	var status = ","+statuss
	$('popbox-content').getElements('input[type=checkbox]').each(function(item,index){
		if (status.indexOf(","+item.value) != -1) {
			item.checked = true;
		}
	});
}
function choosedStatus() {
	statuss = ""	
	$('popbox-content').getElements('input[type=checkbox]').each(function(item,index){
		if (item.checked) {
			statuss += "," + item.value;
		}
	});
	statuss = statuss.substring(1); //delete first ","
	PopBox.close();
	changeData();
}

function chooseProperty() {
	PopBox.pop(document.getElementById("propertylist").innerHTML);
	var property = ","+propertys
	$('popbox-content').getElements('input[type=checkbox]').each(function(item,index){
		if (property.indexOf(","+item.value) != -1) {
			item.checked = true;
		}
	});
}
function choosedProperty() {
	propertys = ""	
	$('popbox-content').getElements('input[type=checkbox]').each(function(item,index){
		if (item.checked) {
			propertys += "," + item.value;
		}
	});
	propertys = propertys.substring(1); //delete first ","
	PopBox.close();
	changeData();
}
</script>
<div style="text-align:right;width:100%;"> Dimension:&nbsp;
    <select id="dimension" onchange="changeData();">
        <option value='engineer'>Engineer</option>
        <option value='property'>Site</option>
        <option value='pm'>PM</option>
        <option value='status'>Status</option>
    </select>
</div>
<div style="margin:10px 0;">
    <div style="float:left; width:300px;">
        <h2>Select date range for the report:</h2>
        <span class="left" style="padding-right:20px;">Start Date &nbsp;&nbsp;
        <input id="date_start" name="date_start" value="<?php if (isset($this->task['date_start'])) echo $this->task['date_start']; else echo date("Y-m-d"); ?>" style="width: 80px;" type="text" readonly />
        <input type="button" id="calendarBeginButton" class="cal" style="width:20px" />
        </span> <span class="left">End Date &nbsp;&nbsp;
        <input id="date_end" name="date_end" value="<?php if (isset($this->task['date_end'])) echo $this->task['date_end']; else echo date("Y-m-d"); ?>" style="width: 80px;" type="text" readonly />
        <input type="button" id="calendarEndButton" class="cal" style="width:20px" />
        </span> &nbsp;&nbsp;
        <input type="button" value="check report!" onClick="changeData()">
        <br />
        <br />
        <a href="#" onclick="chooseUser();return false;">Choose Engineer</a>&nbsp;&nbsp; <a href="#" onclick="chooseStatus();return false;">Choose Status</a>&nbsp;&nbsp; <a href="#" onclick="chooseProperty();return false;">Choose Property</a>
        <!-- choose engineer begin -->
        <div id="userlist">
            <div>
                <?php foreach($this->userList as $user): ?>
                <label class="userlist">
                <input type="checkBox" name="engineer" value="<?php echo $user["id"] ?>">
                <?php echo $user['name']?></label>
                <?php endforeach; ?>
            </div>
            <div class="choosemenu">
                <input type="button" value="Ok" onclick="choosedUser()">
            </div>
        </div>
        <!-- choose engineer end -->
        <!-- choose status begin -->
        <div id="statuslist">
            <div>
                <?php foreach($this->statusList as $key=>$status): ?>
                <label class="statuslist">
                <input type="checkBox" name="engineer" value="<?php echo $key ?>">
                <?php echo $status?></label>
                <?php endforeach; ?>
            </div>
            <div class="choosemenu">
                <input type="button" value="Ok" onclick="choosedStatus()">
            </div>
        </div>
        <!-- choose status end -->
        <!-- choose property begin -->
        <div id="propertylist">
            <div>
                <?php foreach($this->propertyList as $key=>$property): ?>
                <label class="propertylist">
                <input type="checkBox" name="engineer" value="<?php echo $key ?>">
                <?php echo $property?></label>
                <?php endforeach; ?>
            </div>
            <div class="choosemenu">
                <input type="button" value="Ok" onclick="choosedProperty()">
            </div>
        </div>
        <!-- choose property end -->
    </div>
	<div>aaaa</div>
</div>
<div class="cl"></div>
<h2 style="margin-top:20px;">Task Listing:</h2>
<div id="listing" style="display:none;"> </div>
<div id="loadingbox" style="display:none;padding:2px 0px 0px 8px;width:125px;height:20px;text-align:center;position:absolute;top:0px;right:0px;background:#CC0000;color:#fff;z-index:10000;"><b>Loading ...</b></div>
<?php echo $this->render('layouts/__footer.phtml'); ?>